'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller } = app;

  // 首页
  router.get('/', controller.home.index);

  // 验证码相关
  router.get('/api/captcha', controller.captcha.generate); // 生成验证码
  router.post('/api/captcha/verify', controller.captcha.verify); // 验证验证码

  // 认证相关
  router.post('/api/auth/register', controller.auth.register); // 用户注册
  router.post('/api/auth/login', controller.auth.login); // 用户登录
  router.get('/api/auth/user', controller.auth.getUserInfo); // 获取用户信息
  router.get('/api/auth/users', controller.auth.getAllUsers); // 获取所有用户（调试用）
  router.put('/api/auth/profile', controller.auth.updateProfile); // 更新用户资料
  router.put('/api/auth/password', controller.auth.changePassword); // 修改密码

  // 城市相关 CRUD
  router.get('/api/cities', controller.city.index);
  router.get('/api/cities/:id', controller.city.show);
  router.post('/api/cities', controller.city.create);
  router.put('/api/cities/:id', controller.city.update);
  router.delete('/api/cities/:id', controller.city.destroy);
  router.post('/api/cities/batch-delete', controller.city.batchDelete); // 批量删除
  router.post('/api/cities/:id/recommend', controller.city.recommend); // 推荐城市

  // 旅行计划相关 CRUD
  router.get('/api/travel-plans', controller.travelPlan.index);
  router.get('/api/travel-plans/:id', controller.travelPlan.show);
  router.post('/api/travel-plans', controller.travelPlan.create);
  router.put('/api/travel-plans/:id', controller.travelPlan.update);
  router.delete('/api/travel-plans/:id', controller.travelPlan.destroy);
  router.put('/api/travel-plans/:id/audit', controller.travelPlan.audit); // 审核旅行计划

  // 记账预算与支出相关 CRUD
  router.get('/api/budgets', controller.budget.index);
  router.get('/api/budgets/:id', controller.budget.show);
  router.post('/api/budgets', controller.budget.create);
  router.put('/api/budgets/:id', controller.budget.update);
  router.delete('/api/budgets/:id', controller.budget.destroy);

  router.get('/api/expenses', controller.expense.index);
  router.post('/api/expenses', controller.expense.create);
  router.put('/api/expenses/:id', controller.expense.update);
  router.delete('/api/expenses/:id', controller.expense.destroy);

  // 路线规划相关 CRUD
  router.get('/api/routes', controller.route.index);
  router.get('/api/routes/:id', controller.route.show);
  router.post('/api/routes', controller.route.create);
  router.put('/api/routes/:id', controller.route.update);
  router.delete('/api/routes/:id', controller.route.destroy);
  router.get('/api/travel-plans/:planId/routes', controller.route.getByPlanId);

  // 旅行计划相关 CRUD
  router.get('/api/travel-plans', controller.travelPlan.index);
  router.get('/api/travel-plans/:id', controller.travelPlan.show);
  router.post('/api/travel-plans', controller.travelPlan.create);
  router.put('/api/travel-plans/:id', controller.travelPlan.update);
  router.delete('/api/travel-plans/:id', controller.travelPlan.destroy);

  // 记账预算与支出相关 CRUD
  router.get('/api/budgets', controller.budget.index);
  router.get('/api/budgets/:id', controller.budget.show);
  router.post('/api/budgets', controller.budget.create);
  router.put('/api/budgets/:id', controller.budget.update);
  router.delete('/api/budgets/:id', controller.budget.destroy);

  router.get('/api/expenses', controller.expense.index);
  router.post('/api/expenses', controller.expense.create);
  router.put('/api/expenses/:id', controller.expense.update);
  router.delete('/api/expenses/:id', controller.expense.destroy);

  // 心愿单相关
  router.get('/api/wishlist', controller.wishlist.index);
  router.post('/api/wishlist', controller.wishlist.add);
  router.delete('/api/wishlist/:cityId', controller.wishlist.remove);

  // 用户管理相关（管理员）
  router.get('/api/user/list', controller.user.getUserList); // 获取用户列表
  router.get('/api/user/stats', controller.user.getUserStats); // 获取用户统计
  router.get('/api/user/:id', controller.user.getUserDetail); // 获取用户详情
  router.put('/api/user/:id/status', controller.user.updateUserStatus); // 更新用户状态
  router.put('/api/user/:id/role', controller.user.updateUserRole); // 更新用户角色
  router.delete('/api/user/:id', controller.user.deleteUser); // 删除用户

  // 游记相关
  router.post('/api/travel-notes', controller.travelNote.create); // 创建游记
  router.put('/api/travel-notes/:id', controller.travelNote.update); // 更新游记
  router.delete('/api/travel-notes/:id', controller.travelNote.delete); // 删除游记
  router.get('/api/travel-notes/:id', controller.travelNote.getDetail); // 获取游记详情
  router.get('/api/travel-notes', controller.travelNote.getList); // 获取游记列表
  router.get('/api/travel-notes/my/list', controller.travelNote.getMyNotes); // 获取我的游记列表

  // 游记互动相关
  router.post('/api/travel-notes/:id/view', controller.travelNote.increaseViewCount); // 增加浏览量（埋点）
  router.post('/api/travel-notes/:id/like', controller.travelNote.like); // 点赞游记
  router.delete('/api/travel-notes/:id/like', controller.travelNote.unlike); // 取消点赞
  router.post('/api/travel-notes/:id/favorite', controller.travelNote.favorite); // 收藏游记
  router.delete('/api/travel-notes/:id/favorite', controller.travelNote.unfavorite); // 取消收藏

  // 用户收藏和点赞列表
  router.get('/api/travel-notes/favorite/list', controller.travelNote.getFavoriteNotes); // 获取收藏列表
  router.get('/api/travel-notes/like/list', controller.travelNote.getLikeNotes); // 获取点赞列表

  // 游记评论相关
  router.post('/api/travel-notes/:id/comments', controller.travelNote.addComment); // 添加评论
  router.get('/api/travel-notes/:id/comments', controller.travelNote.getComments); // 获取评论列表
  router.delete('/api/travel-notes/comments/:commentId', controller.travelNote.deleteComment); // 删除评论

  // 游记审核（管理员）
  router.put('/api/travel-notes/:id/audit', controller.travelNote.audit); // 审核游记
  router.put('/api/travel-notes/:id/admin', controller.travelNote.adminUpdate); // 管理员更新游记（精选、置顶等）

  // AI 智能审核
  router.post('/api/ai/audit/:id', controller.aiAudit.auditTravelNote); // AI 审核单个游记
  router.post('/api/ai/audit/batch', controller.aiAudit.batchAuditTravelNotes); // AI 批量审核游记
  router.post('/api/ai/audit-plan/:id', controller.aiAudit.auditTravelPlan); // AI 审核单个旅行计划
  router.post('/api/ai/audit-plan/batch', controller.aiAudit.batchAuditTravelPlans); // AI 批量审核旅行计划

  // 文件上传相关
  router.get('/api/upload/token', controller.upload.getToken); // 获取七牛云上传token
  router.post('/api/upload', controller.upload.upload); // 上传单个文件
  router.post('/api/upload/batch', controller.upload.batchUpload); // 批量上传文件

  // 仪表盘统计相关
  router.get('/api/dashboard/stats', controller.dashboard.getStats); // 获取基础统计
  router.get('/api/dashboard/top-cities', controller.dashboard.getTopCities); // 热门城市TOP10
  router.get('/api/dashboard/activity-trend', controller.dashboard.getActivityTrend); // 平台活跃度趋势
  router.get('/api/dashboard/user-growth', controller.dashboard.getUserGrowth); // 用户增长趋势
  router.get('/api/dashboard/content-category', controller.dashboard.getContentCategory); // 内容分类统计

  // 首页推荐相关
  router.get('/api/home/hot-cities', controller.home.getHotCities);
  router.get('/api/home/hot-notes', controller.home.getHotNotes);
  router.get('/api/home/hot-plans', controller.home.getHotPlans);
  router.get('/api/home/featured-community', controller.home.getFeaturedCommunity);
};
